package com.zrwl.poscloud.core.restapi.mobile;

import com.zrwl.poscloud.base.constants.AskforleaveConstants;
import com.zrwl.poscloud.base.enums.EAskforleave;
import com.zrwl.poscloud.base.enums.EStatus;
import com.zrwl.poscloud.commons.exception.ThrowableUtils;
import com.zrwl.poscloud.commons.utils.ResultUtil;
import com.zrwl.poscloud.commons.validator.group.GetList;
import com.zrwl.poscloud.commons.validator.group.Insert;
import com.zrwl.poscloud.core.annotion.AuthorityVerify.AuthorityVerify;
import com.zrwl.poscloud.core.annotion.OperationLogger.OperationLogger;
import com.zrwl.poscloud.xo.service.AskforleaveService;
import com.zrwl.poscloud.xo.service.UserService;
import com.zrwl.poscloud.xo.vo.*;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 请假管理 controller api类
 *
 * @author 刘思童 AutoGenerate
 * @date 2023-03-16
 */
@RestController
@Api(value = "请假管理相关接口", tags = {"请假管理相关接口"})
@RequestMapping("/userAskForLeave")
@Slf4j
public class AskForLeaveRestApi {
    @Autowired
    private AskforleaveService askforleaveService;
    @Autowired
    private UserService userService;
    @AuthorityVerify
    @ApiOperation(value = "获取当前请假信息", notes = "获取当前请假信息", response = String.class)
    @PostMapping("/getRecentlyAskForLeaveInfo")
    public String getRecentlyAskForLeaveInfo(@Validated({GetList.class}) @RequestBody AskforleaveVO askforleaveVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取请假管理列表: {}", askforleaveVO);
        UserVO userVO = userService.getMe();
        UserEmployeeRVO userEmployeeRVO = userVO.getUserEmployeeRVO();
        askforleaveVO.setLeaveEmployeeUid(userEmployeeRVO.getEmployeeUid());
        askforleaveVO.setSubmitUserUid(userVO.getUid());
        return ResultUtil.successWithData(askforleaveService.getRecentlyAskForLeaveInfo(askforleaveVO));
    }
    @AuthorityVerify
    @ApiOperation(value = "获取请假管理列表", notes = "获取请假管理列表", response = String.class)
    @PostMapping("/getAllList")
    public String getAllList(@Validated({GetList.class}) @RequestBody AskforleaveVO askforleaveVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取请假管理列表: {}", askforleaveVO);
        UserVO userVO = userService.getMe();
        UserEmployeeRVO userEmployeeRVO = userVO.getUserEmployeeRVO();
        askforleaveVO.setLeaveEmployeeUid(userEmployeeRVO.getEmployeeUid());
        askforleaveVO.setSubmitUserUid(userVO.getUid());
        return ResultUtil.successWithData(askforleaveService.getAllList(askforleaveVO));
    }
    @AuthorityVerify
    @OperationLogger(value = "新增请假管理")    @ApiOperation(value = "新增请假管理", notes = "新增请假管理", response = String.class)
    @PostMapping("/add")
    public String add(@Validated({Insert.class}) @RequestBody AskforleaveVO askforleaveVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("新增请假管理: {}", askforleaveVO);
        UserVO userVO = userService.getMe();
        askforleaveVO.setSubmitUserUid(userVO.getUid());
        askforleaveVO.setStatus(1);
        return askforleaveService.add(askforleaveVO);
    }
    @AuthorityVerify
    @ApiOperation(value = "获取请假详情", notes = "获取请假详情", response = String.class)
    @PostMapping("/getAskForLeaveInfo")
    public String getAskForLeaveInfo(@Validated({GetList.class}) @RequestBody AskforleaveVO askforleaveVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("获取请假详情: {}", askforleaveVO);
        UserVO userVO = userService.getMe();
        UserEmployeeRVO userEmployeeRVO = userVO.getUserEmployeeRVO();
        askforleaveVO.setLeaveEmployeeUid(userEmployeeRVO.getEmployeeUid());
        askforleaveVO.setSubmitUserUid(userVO.getUid());
        return ResultUtil.successWithData(askforleaveService.getAskForLeaveInfo(askforleaveVO));
    }
    @AuthorityVerify
    @ApiOperation(value = "手机端分页获取请假管理列表", notes = "手机端分页获取请假管理列表", response = String.class)
    @PostMapping("/getAllAskforleaveList")
    public String getAllAskforleaveList(@Validated({GetList.class}) @RequestBody AskforleaveVO askforleaveVO, BindingResult result) {
        ThrowableUtils.checkParamArgument(result);
        log.info("手机端分页获取请假管理列表: {}", askforleaveVO);
        UserVO userVO = userService.getMe();
        UserEmployeeRVO userEmployeeRVO = userVO.getUserEmployeeRVO();
        askforleaveVO.setLeaveEmployeeUid(userEmployeeRVO.getEmployeeUid());
        askforleaveVO.setSubmitUserUid(userVO.getUid());
        return ResultUtil.successWithData(askforleaveService.getAllAskforleaveList(askforleaveVO));
    }
}
